import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { TranslateService } from '@ngx-translate/core';
import { DefaultLanguageService } from '@services/default-language.service';

@Component({
  selector: 'app-transaction-detail',
  templateUrl: './transaction-detail.page.html',
  styleUrls: ['./transaction-detail.page.scss'],
})
export class TransactionDetailPage implements OnInit {
  i18n:any;
  constructor(
    private route : ActivatedRoute,
    public http: HttpClient,
    private defaultLanguageService:DefaultLanguageService,
    private translate: TranslateService
  ) { 
    let defultLanguage = this.defaultLanguageService.getDefaultLanguage();
    this.translate.setDefaultLang(defultLanguage);
    this.translate.use(defultLanguage);
    this.translate.get('myCredit.transaction_page').subscribe((value)=>{
      this.i18n = value;
      this.initPage();
    });

  }
  
  initPage(){

  }

  detailData = {
    discountAmt:'',
    payMethod:'',
    transactionNumber:'',
    merchantsNumber:''
  };
  oldData = {
    amount:'',
    dateTime:''
  };
  httpOptions = {
    headers: new HttpHeaders({ 'Content-Type': 'application/json' })
  };
  
  ngOnInit() {
    console.info(this.route.queryParams);
    this.route.queryParams.subscribe(
      (data:any)=>{
        this.oldData = data;
        const url = '/scm/app/transactionDetail.do';      
        this.http.post(url,data,this.httpOptions).subscribe(
          (response:any)=>{
            console.info("response : "+ JSON.stringify(response));
            // this.datas = this.datas.concat(response);
            if(response.responseBody.payMethod==0){
              response.responseBody.payMethod='Easy Pay';
            }else{
              response.responseBody.payMethod='Other Pay'
            }
            this.detailData=response.responseBody;
          });
      }
    )
  }


  ngAfterViewInit(): void {
    
  }
}
